import React, { Component } from 'react'
import {Input} from 'antd'
export default class baseInput extends Component {
  onChange=(e) => { 
    const {value}=e.target
    const {reg}=this.props
    if((!Number.isNaN(value)&&reg.test(value))||value===''||value==='-'){
      this.props.onChange(value)
    }
  }
  onBlur=(e)=>{
    const {value}=e.target
    const {onBlur,onChange}=this.props
    if(value.charAt(value.length-1)==='.'||value==='-'){
      onChange(value.slice(0,-1))
    }
    if(onBlur){
      onBlur(value)
    }
  }
  render() {
    return (
      <Input
        {...this.props}
        onChange={this.onChange}
        onBlur={this.onBlur}
        onFocus={this.props.onFocus}
      />
    )
  }
}
